package com.tiantian.quanminxiu.presenter;

import com.shenglian.utils.utils.CommonUtils;
import com.tiantian.quanminxiu.api.AnchorService;
import com.tiantian.quanminxiu.utils.ApplicationBase;
import com.tiantian.quanminxiu.utils.Constants;
import com.tiantian.quanminxiu.utils.UserData;
import com.tiantian.quanminxiu.view.DialogUserInfoCardView;

import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by admin on 2016/9/14.
 */
public class DialogUserInfoCardPresent implements Presenter<DialogUserInfoCardView> {

    private DialogUserInfoCardView dialogUserInfoCardView;

    @Override
    public void attachView(DialogUserInfoCardView view) {
        this.dialogUserInfoCardView = view;
    }

    @Override
    public void detachView() {
        this.dialogUserInfoCardView = null;
    }

    public void initUserInfo(){
        dialogUserInfoCardView.initUserInfo();
    }

    public void attentionAnchor(String userid,boolean Cancel){
        dialogUserInfoCardView.Loading_Open();
        ApplicationBase app = ApplicationBase.get(dialogUserInfoCardView.getContext());
        AnchorService service = app.getAnchorService();
        String strCancel = Cancel?"true":"";
        service.user_userinfo_attention(UserData.Current.mid,UserData.Current.sign, Constants.APP_TYPE,userid,strCancel)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(app.defaultSubscribeScheduler())
                .finallyDo(()->{
                    dialogUserInfoCardView.Loading_Close();
                })
                .subscribe(str -> {
                    dialogUserInfoCardView.attentionAnchor();
                }, throwable -> {
                    CommonUtils.showToask(dialogUserInfoCardView.getContext(), throwable.getMessage());
                });
    }
}
